/*
 * @Descripttion: 
 * @version: 
 * @Author: 高月飞
 * @Date: 2023-11-21 12:47:32
 * @LastEditors: 高月飞
 * @LastEditTime: 2023-11-21 17:17:37
 */
import { ElLoading, ElMessage } from 'element-plus';
import { readFile, utils } from "xlsx";
import type { ICustomerData } from "@/types/customer";
import * as XLSX from 'xlsx';
import { writeFile } from 'xlsx';
import { successMessage } from './successMessage';
import { errorMessage } from './errorMessage';


const readExcel = (file: File, tableData: { value: any[] }) => {
    const reader = new FileReader();

    reader.onload = async (e) => {
        const data = e.target?.result;
        if (data) {
            const workbook = XLSX.read(data, { type: 'binary' });
            const sheetName = workbook.SheetNames[0];
            const sheet = workbook.Sheets[sheetName];
            const jsonData = XLSX.utils.sheet_to_json(sheet, { header: 1 });
            const jsonDataWithoutHeader = jsonData.slice(1);

            console.log(jsonDataWithoutHeader);
            jsonDataWithoutHeader.forEach((item) => {
                tableData.value.push(item);
            });

        }
    };

    reader.readAsBinaryString(file);
};

export { readExcel };
